//
//  NetworkConfigration.m
//  PigMarket
//
//  Created by Felix on 2019/4/11.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "NetworkConfigration.h"

#import "PropertyListUtil.h"
#import "ConfigManager.h"

@implementation NetworkConfigration

+ (NetworkConfigration *)defaultNetworkConfiguration {
    
    static NetworkConfigration *configration = nil;
    static dispatch_once_t token;
    
    dispatch_once(&token,^{
        if(configration == nil){
            configration = [[NetworkConfigration alloc] init];
            NSDictionary *networkConfigRoot = [PropertyListUtil getRootWithName:@"NetworkConfig"];
//            NSDictionary *networkConfigRoot = [PropertyListUtil decodePlistWithName:@"edf"];
            NSDictionary *environment = networkConfigRoot[@"Environment"];

            NSString *currentEnvironmentKey = [ConfigManager sharedInstance].environment;
            NSDictionary *currentEnvironment = environment[currentEnvironmentKey];
            NSString *baseApiURL = currentEnvironment[@"BaseApiURL"];
            NSString *clientId = currentEnvironment[@"ClientId"];
            NSString *clientSecret = currentEnvironment[@"ClientSecret"];

            NSString *typeCode = ((NSString *)networkConfigRoot[@"UserType"]);
            NSInteger version = ((NSNumber *)networkConfigRoot[@"Version"]).integerValue;

            configration.baseApiURL = baseApiURL;//基本地址
            configration.typeCode = typeCode;//用户类型
            configration.clientId = clientId;//客户端ID
            configration.clientSecret = clientSecret;//客户端密钥
            configration.version = version;//版本ID,整数
            
            
            NSLog(@"_____________%@ \n %@ \n%@ \n%@ \n%ld________", baseApiURL, typeCode, clientId, clientSecret, version);
            
        }
    });
    
    return configration;
    
}

@end
